package IBBB.view;

import IBBB.model.UserMessage;
import IBBB.model.WordStockMessage;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class NewPlan {

    @FXML
    private StackPane contains;

    @FXML
    private ScrollPane root;

    private UserMessage userMessages;
    private WordStockMessage wordStockMessage;
    private ObservableMap<StringProperty, List<IntegerProperty>> userSchedule;
    private NewPlanStock newPlanPane;
    private ObservableMap<String, Integer> message;


    public void init(UserMessage userMessages, WordStockMessage wordStockMessage) {
        this.userMessages = userMessages;
        this.wordStockMessage = wordStockMessage;
        this.userSchedule = userMessages.getWordStockInfo();
        this.message= wordStockMessage.getMessage();
        this.userSchedule.addListener((MapChangeListener<StringProperty, List<IntegerProperty>>) change -> {
            if (change.wasAdded() || change.wasRemoved()) {
                try {
                    newPlanPane.initialize();
                } catch (IOException e) {
                    // TODO: handle the exception
                    e.printStackTrace();
                }
            }
        });

        try {
            newPlanPane = new NewPlanStock(userMessages, wordStockMessage);
            contains.getChildren().add(newPlanPane);
        } catch (IOException exp) {
            //error to be handled
            System.err.println("error");
        }

    }

}
